package com.neisha.gateway;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.neisha.kit.JobKit;

public class GatewayServlet extends HttpServlet{

	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		StringBuilder res = new StringBuilder("service run result.\r\n");
		Map<String,Integer> exeRes = JobKit.getResult();
		for(Map.Entry<String,Integer> item : exeRes.entrySet()){
			res.append("任务【")
			.append(item.getKey())
			.append("】执行了：").append(item.getValue())
			.append("次。\r\n");
		}
		resp.getOutputStream().write(res.toString().getBytes());
		resp.getOutputStream().close();
	}

}
